<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <input type="text" name="" id="num">
    <input type="text" name="" id="num2">
    <button id="btn">计算</button>
    <script>
        document.getElementById("btn").onclick = function() {
            var _num = document.getElementById("num").value;
            var _num2 = document.getElementById("num2").value;
            var r;
            do {
                r = _num % _num2;
                _num = _num2;
                _num2 = r;

            } while (r != 0);
            document.write(_num);
        }
    </script>
</body>

</html>